﻿package com.extra_archive.framework.utils {
	import flash.text.TextField;
	import flash.text.TextFormat;

	//==================================================================
	//@class name  :  TextFieldUtils.as
	//@author          : vkimone. KimKiJeung  (http://kimkijeung.com)
	//@last update   : 2007. 12. 25
	//@version         : V1.0
	//==================================================================
	
	public class TextFieldUtils {
		
		/**
		 * retrieve the TextField instance with a custom propery.
		 */
		public static function create(width:Number,height:Number,format : TextFormat=null,autoSize:String = "left",
										type:String="dynamic",embed : Boolean=true,antiAlias:String = "advanced",selectable : Boolean=false) : TextField{
			var textField : TextField = new TextField();
			textField.width=width;
			textField.height = height;
			if(format) textField.defaultTextFormat = format;
			textField.autoSize = autoSize;
			textField.embedFonts = embed;
			textField.type = type;
			textField.antiAliasType = antiAlias;
			textField.selectable = selectable;
			
			return textField;
		}
		
		
		public static function truncate(textField : TextField,limitPoint:Number,endString:String) : Boolean {
			var limitIndex:int=textField.getCharIndexAtPoint(limitPoint, textField.height*0.5);
			if(limitIndex!=-1){
				textField.replaceText(limitIndex, textField.length, endString);
				return true;
			}else{
				return false;
			}
		}
	
	}
}
